package com.zycfc.zsf.boot.mq.rabbitmq.destinations;

import com.zycfc.zsf.boot.mq.rabbitmq.type.*;
import org.springframework.amqp.core.*;

public final class TopicDestination implements IDestination
{
    private final String exchangeName;
    private final String queueName;
    private final String routingKey;
    private TopicExchange exchange;
    private Queue queue;
    
    public TopicDestination(final String exchangeName, final String routingKey) {
        this(exchangeName, "topic." + exchangeName, routingKey);
    }
    
    public TopicDestination(final String exchangeName, final String queueName, final String routingKey) {
        if (null == exchangeName || exchangeName.trim().length() == 0) {
            throw new IllegalArgumentException("\u8bf7\u8bbe\u7f6e\u4ea4\u6362\u5668\u540d\u79f0");
        }
        if (null == queueName || queueName.trim().length() == 0) {
            throw new IllegalArgumentException("\u8bf7\u8bbe\u7f6e\u961f\u5217\u540d\u79f0");
        }
        if (null == routingKey || routingKey.trim().length() == 0) {
            throw new IllegalArgumentException("\u8bf7\u8bbe\u7f6e\u8def\u7531Key");
        }
        this.exchangeName = exchangeName.trim();
        this.queueName = queueName.trim();
        this.routingKey = routingKey.trim();
    }
    
    public TopicExchange exchange() {
        if (null == this.exchange) {
            this.exchange = new TopicExchange(this.exchangeName);
        }
        return this.exchange;
    }
    
    @Override
    public Queue queue() {
        if (null == this.queue) {
            this.queue = new Queue(this.queueName);
        }
        return this.queue;
    }
    
    @Override
    public Binding binding() {
        return BindingBuilder.bind(this.queue()).to(this.exchange()).with(this.getRoutingKey());
    }
    
    @Override
    public String getRoutingKey() {
        return this.routingKey;
    }
    
    @Override
    public ExchangeType exchangeType() {
        return ExchangeType.TOPIC;
    }
    
    @Override
    public void resetName(final String namespace, final IDestination destination) {
    }
    
    @Override
    public void setRoutingKey(final String routingKey) {
    }
    
    public String getExchangeName() {
        return this.exchangeName;
    }
    
    public String getQueueName() {
        return this.queueName;
    }
    
    public TopicExchange getExchange() {
        return this.exchange;
    }
    
    public Queue getQueue() {
        return this.queue;
    }
    
    public void setExchange(final TopicExchange exchange) {
        this.exchange = exchange;
    }
    
    public void setQueue(final Queue queue) {
        this.queue = queue;
    }
    
    @Override
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof TopicDestination)) {
            return false;
        }
        final TopicDestination other = (TopicDestination)o;
        final Object this$exchangeName = this.getExchangeName();
        final Object other$exchangeName = other.getExchangeName();
        Label_0055: {
            if (this$exchangeName == null) {
                if (other$exchangeName == null) {
                    break Label_0055;
                }
            }
            else if (this$exchangeName.equals(other$exchangeName)) {
                break Label_0055;
            }
            return false;
        }
        final Object this$queueName = this.getQueueName();
        final Object other$queueName = other.getQueueName();
        Label_0092: {
            if (this$queueName == null) {
                if (other$queueName == null) {
                    break Label_0092;
                }
            }
            else if (this$queueName.equals(other$queueName)) {
                break Label_0092;
            }
            return false;
        }
        final Object this$routingKey = this.getRoutingKey();
        final Object other$routingKey = other.getRoutingKey();
        Label_0129: {
            if (this$routingKey == null) {
                if (other$routingKey == null) {
                    break Label_0129;
                }
            }
            else if (this$routingKey.equals(other$routingKey)) {
                break Label_0129;
            }
            return false;
        }
        final Object this$exchange = this.getExchange();
        final Object other$exchange = other.getExchange();
        Label_0166: {
            if (this$exchange == null) {
                if (other$exchange == null) {
                    break Label_0166;
                }
            }
            else if (this$exchange.equals(other$exchange)) {
                break Label_0166;
            }
            return false;
        }
        final Object this$queue = this.getQueue();
        final Object other$queue = other.getQueue();
        if (this$queue == null) {
            if (other$queue == null) {
                return true;
            }
        }
        else if (this$queue.equals(other$queue)) {
            return true;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $exchangeName = this.getExchangeName();
        result = result * 59 + (($exchangeName == null) ? 43 : $exchangeName.hashCode());
        final Object $queueName = this.getQueueName();
        result = result * 59 + (($queueName == null) ? 43 : $queueName.hashCode());
        final Object $routingKey = this.getRoutingKey();
        result = result * 59 + (($routingKey == null) ? 43 : $routingKey.hashCode());
        final Object $exchange = this.getExchange();
        result = result * 59 + (($exchange == null) ? 43 : $exchange.hashCode());
        final Object $queue = this.getQueue();
        result = result * 59 + (($queue == null) ? 43 : $queue.hashCode());
        return result;
    }
    
    @Override
    public String toString() {
        return "TopicDestination(exchangeName=" + this.getExchangeName() + ", queueName=" + this.getQueueName() + ", routingKey=" + this.getRoutingKey() + ", exchange=" + this.getExchange() + ", queue=" + this.getQueue() + ")";
    }
}
